package com.zhouchao.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zhouchao.bean.Visit;


public class VisitDao {
	public List<Visit> visitList(Connection con)throws Exception {
		List<Visit> infolist = new ArrayList<Visit>();
		String sql = "select * from t_visit order by id desc";
		PreparedStatement pstmt = con.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		while(rs.next()) {
			Visit visit=new Visit();
			
			
			visit.setName(rs.getString("name"));
			visit.setTel(rs.getString("tel"));
			visit.setStuname(rs.getString("stuname"));
			visit.setStunum(rs.getString("stunum"));
			visit.setDate(rs.getString("date"));
			visit.setTemp(rs.getString("temp"));
			infolist.add(visit);
		}
		return infolist;
	}
	public Visit visitList(Connection con,String id,String dorm)throws Exception {
		Visit visit=new Visit();
		String sql = "select * from t_visit where dormid='"+id+"' dorm='"+dorm+"'";
		PreparedStatement pstmt = con.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		while(rs.next()) {
			visit.setName(rs.getString("name"));
			visit.setTel(rs.getString("tel"));
			visit.setStuname(rs.getString("stuname"));
			visit.setStunum(rs.getString("stunum"));
			visit.setDate(rs.getString("date"));
			visit.setTemp(rs.getString("temp"));
			
			System.out.println(visit);
		}
		return visit;
	}
	//添加消息
	public int intovisit(Connection con,Visit visit) throws Exception{
		String sql = "insert into t_visit values(null,?,?,?,?,?,?)";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, visit.getName());
		pstmt.setString(2, visit.getTel());
		pstmt.setString(3, visit.getStuname());
		pstmt.setString(4, visit.getStunum());
		pstmt.setString(5, visit.getDate());
		pstmt.setString(6, visit.getTemp());
		System.out.println(sql);
		return pstmt.executeUpdate();
	}
	
}
